package com.opensource.svgaplayer.entities;

import com.opensource.svgaplayer.proto.FrameEntity;
import com.opensource.svgaplayer.proto.Layout;
import com.opensource.svgaplayer.proto.ShapeEntity;
import com.opensource.svgaplayer.proto.Transform;
import com.opensource.svgaplayer.utils.Intrinsics;
import com.opensource.svgaplayer.utils.SVGARect;
import ohos.agp.utils.Matrix;
import ohos.agp.utils.TextTool;
import ohos.utils.zson.ZSONArray;
import ohos.utils.zson.ZSONObject;
import java.util.ArrayList;
import java.util.List;

/**
 * ex.
 *
 * @author wl
 * @since 2021-06-28
 */
public class SVGAVideoSpriteFrameEntity {
    private double alpha = 0.0d;
    private SVGARect layout;
    private Matrix transform;
    private SVGAPathEntity maskPath;
    private List<SVGAVideoShapeEntity> shapes;

    /**
     * SVGAVideoSpriteFrameEntity
     * @param obj ZSONObject
     */
    public SVGAVideoSpriteFrameEntity(ZSONObject obj) {
        Intrinsics.checkParameterIsNotNull(obj, "obj");
        this.layout = new SVGARect(0.0, 0.0, 0.0, 0.0);
        this.transform = new Matrix();
        this.shapes = new ArrayList();
        this.alpha = obj.getDoubleValue("alpha");
        ZSONObject ZSONObject = obj.getZSONObject("layout");
        if (ZSONObject != null) {
            this.layout = new SVGARect(
                    ZSONObject.getDouble("x") == null ? 0.0 : ZSONObject.getDoubleValue("x"),
                    ZSONObject.getDouble("y") == null ? 0.0 : ZSONObject.getDoubleValue("y"),
                    ZSONObject.getDouble("width") == null ? 0.0 : ZSONObject.getDoubleValue("width"),
                    ZSONObject.getDouble("height") == null ? 0.0 : ZSONObject.getDouble("height"));
        }
        ZSONObject ZSONObject1 = obj.getZSONObject("transform");
        if (ZSONObject1 != null) {
            float[] arr = new float[9];
            double a = 1.0;
            if (ZSONObject1.getDouble("a") != null) {
                a = ZSONObject1.getDoubleValue("a");
            }
            double b = ZSONObject1.getDoubleValue("b");
            double c = ZSONObject1.getDoubleValue("c");
            double d = 1.0;
            if (ZSONObject1.getDouble("d") != null) {
                d = ZSONObject1.getDoubleValue("d");
            }
            double tx = ZSONObject1.getDoubleValue("tx");
            double ty = ZSONObject1.getDoubleValue("ty");
            arr[0] = (float) a;
            arr[1] = (float) c;
            arr[2] = (float) tx;
            arr[3] = (float) b;
            arr[4] = (float) d;
            arr[5] = (float) ty;
            arr[6] = (float) 0.0;
            arr[7] = (float) 0.0;
            arr[8] = (float) 1.0;
            this.transform.setElements(arr);
        }
        String clipPath = obj.getString("clipPath");
        if (!TextTool.isNullOrEmpty(clipPath)) {
            this.maskPath = new SVGAPathEntity(clipPath);
        }
        ZSONArray jsonArrayShapes = obj.getZSONArray("shapes");
        if (jsonArrayShapes != null) {
            List<SVGAVideoShapeEntity> mutableList = new ArrayList();
            for (int i = 0; i < jsonArrayShapes.size(); i++) {
                ZSONObject ZSONObject2 = jsonArrayShapes.getZSONObject(i);
                if (ZSONObject2 != null) {
                    mutableList.add(new SVGAVideoShapeEntity(ZSONObject2));
                }
            }
            this.shapes = mutableList;
        }
    }

    /**
     * SVGAVideoSpriteFrameEntity
     * @param obj FrameEntity
     */
    public SVGAVideoSpriteFrameEntity(FrameEntity obj) {
        this.layout = new SVGARect(0.0, 0.0, 0.0, 0.0);
        this.transform = new Matrix();
        this.shapes = new ArrayList();
        this.alpha = obj.alpha;
        Layout layout = obj.layout;
        if (layout != null) {
            this.layout = new SVGARect(layout.x, layout.y, layout.width, layout.height);
        }
        Transform transform1 = obj.transform;
        if (transform1 != null) {
            float[] arr = new float[9];
            float a = transform1.a;
            float b = transform1.b;
            float c = transform1.c;
            float d = transform1.d;
            float tx = transform1.tx;
            float ty = transform1.ty;
            arr[0] = a;
            arr[1] = c;
            arr[2] = tx;
            arr[3] = b;
            arr[4] = d;
            arr[5] = ty;
            arr[6] = 0.0f;
            arr[7] = 0.0f;
            arr[8] = 1.0f;
            this.transform.setElements(arr);
        }
        String clipPath = obj.clipPath;
        if (!TextTool.isNullOrEmpty(clipPath)) {
            maskPath = new SVGAPathEntity(clipPath);
        }
        List<ShapeEntity> shapesList = obj.shapes;
        if (shapesList != null && shapesList.size() > 0) {
            List<SVGAVideoShapeEntity> list = new ArrayList<>();
            for (ShapeEntity it : shapesList) {
                SVGAVideoShapeEntity entity = new SVGAVideoShapeEntity(it);
                list.add(entity);
            }
            this.shapes = list;
        }
    }

    /**
     * getAlpha
     * @return double
     */
    public double getAlpha() {
        return this.alpha;
    }

    /**
     * setAlpha
     * @param alpha double
     */
    public void setAlpha(double alpha) {
        this.alpha = alpha;
    }

    /**
     * getLayout
     * @return SVGARect
     */
    public SVGARect getLayout() {
        return this.layout;
    }

    /**
     * setLayout
     * @param layout SVGARect
     */
    public void setLayout(SVGARect layout) {
        Intrinsics.checkParameterIsNotNull(layout, "<set-?>");
        this.layout = layout;
    }

    /**
     * getTransform
     * @return Matrix
     */
    public Matrix getTransform() {
        return this.transform;
    }

    /**
     * setTransform
     * @param transform Matrix
     */
    public void setTransform(Matrix transform) {
        Intrinsics.checkParameterIsNotNull(transform, "<set-?>");
        this.transform = transform;
    }

    /**
     * getMaskPath
     * @return SVGAPathEntity
     */
    public SVGAPathEntity getMaskPath() {
        return this.maskPath;
    }

    /**
     * setMaskPath
     * @param maskPath SVGAPathEntity
     */
    public void setMaskPath(SVGAPathEntity maskPath) {
        this.maskPath = maskPath;
    }

    /**
     * getShapes
     * @return List<SVGAVideoShapeEntity>
     */
    public List<SVGAVideoShapeEntity> getShapes() {
        return this.shapes;
    }

    /**
     * setShapes
     * @param shapes List<SVGAVideoShapeEntity>
     */
    public void setShapes(List<SVGAVideoShapeEntity> shapes) {
        Intrinsics.checkParameterIsNotNull(shapes, "<set-?>");
        this.shapes = shapes;
    }
}
